<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

<div id="id_panel">
</div>

<script th:inline="javascript">
	var dto = $.parseJSON(JSON.stringify([[${dto}]]));

	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
				form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
				{
					id:'id_panel', // 页面容器ID
					dto: dto
				}
		);

		if([[${onProcess}]]=='1'){
			//隐藏头部按钮
			$('#' + formObj.c.id_header).hide();
		}

		// // 设置复选框回调函数
		formObj.matchValuesAfterModalSelectCheckbox = function(rowSelected, extraData) {
			var materialCnList = [];
			var materialEnList = [];
			var materialIdList = [];
			for (var i = 0; i < rowSelected.length; i++) {
				var obj = rowSelected[i];
				materialCnList.push(obj.materialCn)
				if (obj.materialEn != '' && obj.materialEn != null && obj.materialEn != undefined){
					materialEnList.push(obj.materialEn)
				}
				materialIdList.push(obj.id)
			}
			if (materialCnList.length != 0){
				formObj.setValueByName("materialCn", materialCnList)
				formObj.setValueByName("materialId", materialIdList)
			}
			if (materialEnList.length != 0){
				formObj.setValueByName("materialEn", materialEnList)
			}
		}
		$('#' + formObj.c.id_form).find('i[lay-filter="buttontext_modal_checkbox"]').on('click',function (e) {
			var selectedData = [];
			let materialCn = formObj.getValueByName("materialCn");
			let materialEn = formObj.getValueByName("materialEn");
			let materialId = formObj.getValueByName("materialId");
			if (materialCn != undefined) {
				let materialCnList = materialCn.split(",");
				let materialEnList = [];
				if (materialEn != null && materialEn != undefined){
					materialEnList = materialEn.split(",");
				}
				let materialIdList = materialId.split(",");
				//回填数据的代码
				for (var i = 0; i < materialCnList.length; i++) {
					var row = {};
					row.materialCn = materialCnList[i];
					row.materialEn = materialEnList[i];
					row.id = materialIdList[i];
					selectedData.push(row);
				}
			}

			layui.YsModal.init({
				modalKey: 'TB_BaseinfoSpcz',
				type: 'checkbox',
				uniqueKey: 'materialCn',
				parentObj: formObj,
				selectedData: selectedData
			})
		});




	});


</script>

</body>
</html>